<!DOCTYPE html>
<html>
<head>
	<title>ref</title>
	<meta charset="UTF-8">
	<script src="./vue.js"></script>
</head>
<body>
	<div id="app">
		 <counter ref="one" @change="handleChange"></counter>
		 <counter ref="two" @change="handleChange"></counter>
		 <div>{{total}}</div>
	</div>

	<script>
		Vue.component('counter', {
			template: `<div @click="handleClick">{{count}}</div>`,
			data: function () {
				return {
					count: 0
				}
			},
			methods: {
				handleClick: function () {
					this.count++
					this.count++
					this.$emit('change')
				}
			}
		})

		var app = new Vue({
			el: '#app',
			data: {
				total: 0,
			},
			methods: {
				handleChange: function () {
					this.total = this.$refs.one.count +this.$refs.two.count
				}
			}
		})
	</script>

</body>
</html>